package kin.converter;

import java.util.List;   

import org.apache.commons.beanutils.ConvertUtilsBean;  
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
import org.springframework.core.type.filter.AnnotationTypeFilter;
  
public class ARPConvertUtilsBean extends ConvertUtilsBean {  
  
    @Override  
    public void deregister() {  
        super.deregister(); 
        scanPackage("kin.test");
        scanPackage("kin.bean.system");
        scanPackage("kin.bean.customer");
        scanPackage("kin.bean.security");
        register(new CollectionTypeConverter(), List.class);  
    }  
    
    private void scanPackage(String packageName){
    	ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
		scanner.addIncludeFilter(new AnnotationTypeFilter(javax.persistence.Entity.class));
		for (BeanDefinition beanDefinition : scanner.findCandidateComponents(packageName)) {
			Class cls=null;
			try {
				cls=Class.forName(beanDefinition.getBeanClassName());
				
				
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			register(new BeanTypeConverter(), cls);
		}
    }
}  
